import { Component, Injector, ViewEncapsulation } from '@angular/core';
import { Http } from '@angular/http';
import { VideoDto, EntityDtoOfInt64, HomePageServiceProxy, ArticleDto, TagDto, CommentsDto } from '@shared/service-proxies/service-proxies';
import { NotifyService } from '@abp/notify/notify.service';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { ActivatedRoute } from '@angular/router';

@Component({
  templateUrl: './post-detail.component.html',
  styleUrls: ['./post-detail.component.css'],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})
export class PostDetailComponent extends AppComponentBase {

  //Filters
  advancedFiltersAreShown = false;
  filterText = '';


  public article: ArticleDto = new ArticleDto();
  public comments: CommentsDto[];
  tags: TagDto[];

  constructor(
    injector: Injector,
    private _http: Http,
    private _notifyService: NotifyService,
    private _homepage: HomePageServiceProxy,
    private activatedRoute: ActivatedRoute) {
    super(injector);
    this.getarticle();
    this.getComment();
  }


  getarticle(): void {
    let postId = this.activatedRoute.snapshot.paramMap.get('id');
    this.article = new ArticleDto();
    this._homepage.getArticleByID(Number(postId))
      .subscribe(result => this.article = result);
  }

  getComment(): void {
    this.comments = new Array<CommentsDto>();
    let postId = this.activatedRoute.snapshot.paramMap.get('id');

    this._homepage.getCommentsByArticleId(Number(postId))
      .subscribe(result => {
        this.comments = result.items;
      });
  }
  getTags(): void {
    this._homepage.getTags().subscribe(result => this.tags = result.items);
  }
}






